package com.platform.api.bzproject.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.platform.api.bzproject.dao.BzQuotationsMapper;
import com.platform.api.bzproject.model.BzQuotations;
import com.platform.common.core.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

/**
 * @author guoyunfei on 2021/7/27 20:51
 * @className BzQuotationsController
 * @description TODO
 * @Version 1.0
 * 源码联系微信：2549789059
 */
@Api(tags = "语录信息")
@RestController
@RequestMapping("{appid}/quotations")
public class BzQuotationsController {

    @Autowired
    private BzQuotationsMapper quotationsDao;


    @ApiOperation(value = "获取随机语录", notes="获取随机语录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "appid", value = "小程序appid", required = true, dataType = "String"),
    })
    @GetMapping("getRanQuotation")
    public Result getRandomData(@PathVariable String appid){
        QueryWrapper<BzQuotations> queryWrapper = new QueryWrapper<>();

        //queryWrapper.eq("appid",appid);

        //获取语录列表
        List<BzQuotations> list = quotationsDao.selectList(null);

        Random ra =new Random();
        int rand = ra.nextInt(list.size()) + 1;

        queryWrapper.eq("inde",rand);
        BzQuotations quotation = quotationsDao.selectOne(queryWrapper);

        Map<String,Object> map = new HashMap<>();
        map.put("share_image",quotation.getImg());
        map.put("share_title",quotation.getQutotation());

        return Result.success(map);
    }


}
